package mest.controller.hank;

import com.alibaba.fastjson.JSON;
import mest.entity.plan_productjob_saleout;
import mest.entity.plan_productjob_takematerial;
import mest.service.hank.PlanProductjobSaleoutService;
import mest.util.ResultObj;
import mest.util.mestUtil;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname PlanProductjobSaleout
 * @Description TODO
 * @Date 2019/12/8 15:10
 * @Created by 18416
 * @Auther: henk
 */
@RestController
@RequestMapping("/PlanProductjobSaleout")
@CrossOrigin
public class PlanProductjobSaleout {

    @Resource
    private PlanProductjobSaleoutService ppsos;

    /**
     * 1.批量插入(物料清单)
     * 2.果魔君~给相应的list给我
     * @param record
     * @return
     */
    @RequestMapping("/inserList")
    public Object inserList(@RequestBody List<plan_productjob_saleout> record , HttpServletRequest request){
        String theirDb = mestUtil.getCompanyDB(request);
        int i = ppsos.intsertList(record,theirDb);

        if(i>0){
            //System.out.println("执行成功");
        }


        return ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
    }


    /**
     * 通过父级ID分页查询方法
     * @param index
     * @param pageSize
     * @param psId
     * @return
     */
    @RequestMapping("/queryAllModel")
    public Object queryAllModel(@RequestParam Integer index,
                                @RequestParam Integer pageSize,
                                Integer psId, HttpServletRequest request) {
        Long start = System.currentTimeMillis();
        String theirDb = mestUtil.getCompanyDB(request);
        System.out.println("psId================="+psId);
        Map<String, Object> modelMap = new HashMap<String, Object>();
        try {
            List<Map> eModel = ppsos.queryAllModel_byId(index, pageSize, psId,theirDb);
            if (!ObjectUtils.isEmpty(eModel)) {
                modelMap.put("data", eModel);
                modelMap.put("msg", "success");
                modelMap.put("code", 0);
                modelMap.put("count", ppsos.findCount(psId,theirDb));
                modelMap.put("耗时/ms:", (System.currentTimeMillis() - start));
            } else {
                modelMap.put("msg", "此对象为空值");
            }

        } catch (Exception e) {
            modelMap.put("msg", "fales");
            modelMap.put("errmsg", e.toString());
        }
        return JSON.toJSONString(modelMap);
    }


}
